﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DoeLibsMVC.Models;
using DoeObjects;

namespace DoeLibsMVC.Controllers
{
    public class LoanableLocationCategoryController : BaseController
    {
        /// <summary>
        /// lists all the categories from the user
        /// </summary>
        /// <returns></returns>
        [Authorize(Roles=Security.UserCategoryHelper.STAFF_CATEGORY)]
        public ActionResult GetMine()
        {
            return View();
        }

        [Authorize(Roles = Security.UserCategoryHelper.STAFF_CATEGORY)]
        public ActionResult Get(int id)
        {
            ViewBag.categoryId = id;
            return View();
        }

        /// <summary>
        /// edit a category
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize(Roles = Security.UserCategoryHelper.STAFF_CATEGORY)]
        public ActionResult Edit(int id)
        {
            LoanableCategory cat = LoanableCategory.getById(id);
            if (cat == null)
            {
                return new HttpNotFoundResult();
            }

            ViewBag.categoryId = id;

            EditLoanableLocationCategoryModel editModel = new EditLoanableLocationCategoryModel();
            editModel.Name = cat.Name;

            return View(editModel);
        }

        ///// <summary>
        ///// edit a category
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Authorize(Roles = Security.UserCategoryHelper.STAFF_CATEGORY)]
        //public ActionResult Edit(EditLoanableLocationCategoryModel model, int id)
        //{
        //    LoanableCategory cat = LoanableCategory.getById(id);
        //    if (cat == null)
        //    {
        //        ViewBag.success = false;
        //        ViewBag.message = "No locationcategory for the given ID found";

        //        return View();
        //    }

        //    if (cat.Owner.UserId != User.UserId)
        //    {
        //        ViewBag.success = false;
        //        ViewBag.message = "You can only edit your locationcategrories";

        //        return View();
        //    }

        //    cat.Name = model.Name;

        //    if (cat.save())
        //    {
        //        ViewBag.success = true;
        //        ViewBag.message = "Category updated";
        //    }
        //    else
        //    {
        //        ViewBag.success = false;
        //        ViewBag.message = "Category could not be updated";
        //    }

        //    return View(model);
        //}
    }
}
